// API接口统一管理
import {get, post, put, del, callFunction} from './request.js'
import config from "./config";

// 用户认证与管理模块
export const userApi = {
    // 检查token有效性
    checkToken: () => callFunction({name: 'user-center', data: {action: 'checkToken'}}),

    // 发送短信验证码
    sendSmsCode: (data) => callFunction({name: 'user-center', data: {action: 'sendSmsCode', data}}),

    // 短信登录
    loginBySms: (data) => callFunction({name: 'user-center', data: {action: 'loginBySms', data}}),

    // 设置邮箱验证码
    setVerifyCode: (data) => callFunction({name: 'user-center', data: {action: 'setVerifyCode', data}}),

    // 邮箱登录
    loginByEmail: (data) => callFunction({name: 'user-center', data: {action: 'loginByEmail', data}})
}

// 公文处理模块
export const documentApi = {
    // 获取公文编号和流程内容
    getSN: (data) => callFunction({name: 'gongwen', data: {name: 'getSN', data}}),

    // 获取待办公文列表
    getList: (data) => callFunction({name: 'gongwen', data: {name: 'gwGetDB', data}}),

    // 获取公文详情
    getDetail: (data) => callFunction({name: 'gongwen', data: {name: 'gwGetDetail', data}})
}

// 日志管理模块
export const dailyApi = {
    // 获取日志列表
    getList: (data) => callFunction({name: 'daily', data: {name: 'dailyList', data}}),

    // 添加工作日志
    add: (data) => callFunction({name: 'daily', data: {name: 'dailyAdd', data}})
}

// 考勤打卡模块
export const attendanceApi = {
    // 打卡触发器
    trigger: () => callFunction({name: 'clockIn', data: {name: 'ClockInAddTrigger'}}),

    // 添加打卡记录
    add: (data) => callFunction({name: 'clockIn', data: {name: 'ClockInAdd', data}}),

    // 打卡
    punch: (data) => callFunction({name: 'clockIn', data: {name: 'punch', data}}),

    // 解析经纬度
    parseLocation: (data) => callFunction({name: 'clockIn', data: {name: 'parseLocation', data}}),

    // 获取考勤记录
    getAttendanceRecords: (data) => callFunction({name: 'clockIn', data: {name: 'getAttendanceRecords', data}})
}

// 流程管理模块
export const flowApi = {
    // 获取流程编号
    getSN: () => callFunction({name: 'flow', data: {name: 'getSN'}}),

    // 添加流程申请
    add: (data) => callFunction({name: 'flow', data: {name: 'flowAdd', data}}),

    // 删除流程申请
    remove: (data) => callFunction({name: 'flow', data: {name: 'flowRemove', data}}),

    // 获取流程详情
    getDetail: (data) => callFunction({name: 'flow', data: {name: 'flowGetDetail', data}})
}

// 邮件模块
export const emailApi = {
    // 获取邮件详情
    getDetail: (data) => callFunction({name: 'email', data: {name: 'emailDetail', data}}),

    // 恢复邮件
    recovery: (data) => callFunction({name: 'email', data: {name: 'recoveryEmail', data}}),

    // 添加邮件
    add: (data) => callFunction({name: 'email', data: {name: 'emailAdd', data}}),

    // 更新邮件
    update: (data) => callFunction({name: 'email', data: {name: 'emailUpdate', data}})
}

// 问卷调查模块
export const surveyApi = {
    // 获取问卷详情
    getDetail: (data) => callFunction({name: 'survey', data: {name: 'getSurveyDetail', data}})
}

// 应用更新模块
export const appApi = {
    // 检查应用更新
    checkVersion: (data) => callFunction({name: 'check-version', data})
}

// // 张恒阳模块
// export const zhyApi = {
//     // 获取单号
//     getSN: () => post(config.apiPaths['zhy'].getSN),
//
//     // 添加申请
//     add: (data) => post(config.apiPaths['zhy'].zhyAdd, data),
//
//     // 删除申请
//     remove: (data) => post(config.apiPaths['zhy'].zhyRemove, data),
//
//     // 获取详情
//     getDetail: (data) => post(config.apiPaths['zhy'].zhyGetDetail, data),
//
//     // 获取流程列表（新增）
//     getList: (data) => post(config.apiPaths['zhy'].zhyGetList, data)
//
//
//
// }

// 张恒阳模块
export const zhyApi = {
    // 获取单号
    getSN: () => post(config.apiPaths['zhy'].getSN),

    // 添加申请
    add: (data) => post(config.apiPaths['zhy'].zhyAdd, data),

    // 删除申请
    remove: (data) => post(config.apiPaths['zhy'].zhyRemove, data),

    // 获取详情
    getDetail: (data) => post(config.apiPaths['zhy'].zhyGetDetail, data),

    // 获取流程列表（新增）
    getList: (data) => post(config.apiPaths['zhy'].zhyGetList, data),

    // 获取待审批任务列表（新增）
    getTasks: (data) => post(config.apiPaths['zhy'].getTasks, data),

    // 审批任务（新增）
    approveTask: (data) => post(config.apiPaths['zhy'].approveTask, data)
}


// 新增：联系人管理模块
export const contactsApi = {
    add: (data) => callFunction({name: 'contacts', data: {name: 'add', data}}),
    update: (data) => callFunction({name: 'contacts', data: {name: 'update', data}}),
    delete: (data) => callFunction({name: 'contacts', data: {name: 'delete', data}}),
    // 获取联系人详情
    getDetail: (data) => callFunction({name: 'contacts', data: {name: 'getDetail', data}}),
    // 获取联系人列表
    getList: (data) => callFunction({name: 'contacts', data: {name: 'getList', data}}),
    // 获取公司信息
    getCompanyInfo: (data) => callFunction({name: 'contacts', data: {name: 'getCompanyInfo', data}}),
    // 获取部门列表
    getDepartmentList: (data) => callFunction({name: 'contacts', data: {name: 'getDepartmentList', data}}),
}
// 新增：密码管理模块
export const pwdApi = {
    update: (data) => callFunction({name: 'pwd', data: {name: 'update', data}})
}

// 新增：反馈管理模块
export const feedbackApi = {
    add: (data) => callFunction({name: 'feedback', data: {name: 'add', data}}),
    update: (data) => callFunction({name: 'feedback', data: {name: 'update', data}}),
    delete: (data) => callFunction({name: 'feedback', data: {name: 'delete', data}}),
    getDetail: (data) => callFunction({name: 'feedback', data: {name: 'getDetail', data}}),
    getList: (data) => callFunction({name: 'feedback', data: {name: 'getList', data}})
}

// 新增：设置模块
export const settingApi = {
    update: (data) => callFunction({name: 'setting', data: {name: 'update', data}})
}

// 新增：部门管理模块
export const departmentApi = {
    update: (data) => callFunction({name: 'department', data: {name: 'update', data}})
}

// 新增：联系我们模块
export const contactUsApi = {
    add: (data) => callFunction({name: 'contactUs', data: {name: 'add', data}}),
    update: (data) => callFunction({name: 'contactUs', data: {name: 'update', data}}),
    getDetail: (data) => callFunction({name: 'contactUs', data: {name: 'getDetail', data}})
}

// 新增：聊天模块 (缺少的模块)
export const chatApi = {
    // 获取聊天列表
    getChatList: (data) => callFunction({name: 'chat', data: {name: 'getChatList', data}}),
    sendMessage: (data) => callFunction({name: 'chat', data: {name: 'sendMessage', data}}),
    getChatData: (data) => callFunction({name: 'chat', data: {name: 'getChatData', data}})
}

// 导出所有API模块
export default {
    user: userApi,
    document: documentApi,
    daily: dailyApi,
    attendance: attendanceApi,
    flow: flowApi,
    email: emailApi,
    survey: surveyApi,
    app: appApi,
    contacts: contactsApi,
    feedback: feedbackApi,
    setting: settingApi,
    department: departmentApi,
    pwd: pwdApi,
    zhy:zhyApi,
    contactUs: contactUsApi,
    chat: chatApi, // 添加chat模块到导出中
    // 原始请求方法
    get,
    post,
    put,
    delete: del,
    callFunction
}